﻿using System;
using System.Collections;
using System.Collections.Generic;
using VirtualDeveloper.Filters;
using Xunit;

namespace UnitTest
{
    public class RandomEnumerableTest
    {
        [Fact]
        public void Enumerator_test()
        {
            var random = new RandomEnumerable<string>("hello", "toto", "titi", "tata", "tutu");

            Assert.NotNull(((IEnumerable)random).GetEnumerator());

            var enumerator = random.GetEnumerator();

            enumerator.Dispose();
            enumerator.Reset();

            Assert.NotNull(((IEnumerator)enumerator).Current);
        }

        [Fact]
        public void Random_enumerable()
        {
            var random = new RandomEnumerable<string>("hello", "toto", "titi", "tata", "tutu").GetEnumerator();

            var previous = GetNext(random, string.Empty);

            for (var i = 0; i < 10; i++)
            {
                var next = GetNext(random, previous);
                Assert.NotEqual(previous, next);

                previous = next;
            }
        }

        private static string GetNext(IEnumerator<string> enumerator, string previous)
        {
            var current = previous;

            while (string.Equals(current, previous, StringComparison.InvariantCultureIgnoreCase))
            {
                enumerator.MoveNext();
                current = enumerator.Current;
            }
            return current;
        }
    }
}
